home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / MPW / gzip 1.2.2 / cextras-1.0 / isatty.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-08  |  1.3 KB  |  58 lines  |  [TEXT/MPS ]

  1. /*
  2.     isatty.c -- return 1 if file descriptor is an open window
  3.              -- return 0 if file descriptor is a file
  4.     
  5.     Copyright (c) 1993 Anthony C. Ard.
  6.  
  7.     This program is free software; you can redistribute it and/or
  8.     modifiy it under the terms of the GNU General Public License
  9.     as published by the Free Software Foundation; either version 2
  10.     of the License, or (at your option) any later version.
  11.     
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15.     GNU General Public License for more details.
  16.     
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. #include <errno.h>
  23. #include <IOCtl.h>
  24.  
  25. int isatty( int fd )
  26. {
  27.     long result;
  28.     int r, old_errno;
  29.  
  30.     old_errno = errno;    /* preserve errno */
  31.     
  32.     r = ioctl( fd, FIOINTERACTIVE, &result );
  33.     
  34.     errno = old_errno;    /* restore old errno */
  35.  
  36.     if( r == 0 ) return 1;
  37.     return 0;
  38. }
  39.  
  40. #ifdef TEST
  41. # include <stdio.h>
  42. # include <string.h>
  43.  
  44. int main()
  45. {
  46.     int r, i;
  47.     
  48.     for( i = 0; i < 4; i++ ) {
  49.         r = isatty( i );
  50.         printf( "### isatty( %d ): result = %d; errors (%d,%s)\n",
  51.                 i, r, errno, strerror(errno) );
  52.     }
  53.     
  54.     return 0;
  55. }
  56.  
  57. #endif TEST
  58.